//Saturday, December 05 2009
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class MinimalDifference
{
public:
	int findNumber(int A, int B, int C)
	{
		int ret = 10000000;
		int idx = -1;
		int mmin = min(A, B);
		int mmax = max(A, B);
		for(int i=mmin; i<=mmax; i++)
		{
			int temp = abs(sumofdigit(i) - sumofdigit(C));
			if( temp < ret)
			{
				ret = temp;
				idx = i;
			}
		}
		return idx;
	}
	int sumofdigit(int A)
	{
		int sum = 0;
		while(A > 0)
		{
			sum += A % 10;
			A /= 10;
		}
		return sum;
	}
};
